package zxing.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

import org.litepal.crud.DataSupport;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Hashtable;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.virtualapp.R;
import io.virtualapp.abs.ui.VActivity;
import io.virtualapp.bean.MakeBean;
import io.virtualapp.bean.NumBean;

public class QRHttpActivity extends VActivity {
    @BindView(R.id.editor_http)
    EditText editor_http;
    @BindView(R.id.but)
    Button but;
    @BindView(R.id.head_back)
    ImageView head_back;
    @BindView(R.id.head_center_title)
    TextView head_center_title;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qrhttp);
        ButterKnife.bind(this);
        initView();
    }

    public void initView() {
        editor_http.setSelection(editor_http.getText().length());
        head_center_title.setText("网址二维码");
        head_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (editor_http.getText().toString() == null || "https://".equals(editor_http.getText().toString()) || editor_http.getText().toString().length() < 1) {
                    Toast.makeText(QRHttpActivity.this, "网址不正确！", Toast.LENGTH_SHORT).show();
                    return;
                }
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
                Date date = new Date(System.currentTimeMillis());
                String n = simpleDateFormat.format(date);
                MakeBean user = new MakeBean();
                user.setName(n);
                user.setTit(editor_http.getText().toString() + "");
                user.save();
                NumBean numBean = new NumBean();
                if (DataSupport.findFirst(NumBean.class) != null) {
                    DataSupport.deleteAll(NumBean.class);
                }
                numBean.setNum(2);
                numBean.save();
                Intent intent = new Intent(getActivity(), CodeDisplayActivity.class);
                intent.putExtra("data", editor_http.getText().toString() + "");
                intent.putExtra("title", "网址二维码");
                startActivity(intent);
            }
        });
    }
}

